package com.yangrong.newsservice.service.impl;

import com.yangrong.newsservice.dao.TbArticleTypeDao;
import com.yangrong.newsservice.entity.TbArticleTypeEntity;
import com.yangrong.newsservice.service.TbArticleTypeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yangrong.common.utils.PageUtils;
import com.yangrong.common.utils.Query;


@Service("tbArticleTypeService")
public class TbArticleTypeServiceImpl extends ServiceImpl<TbArticleTypeDao, TbArticleTypeEntity> implements TbArticleTypeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TbArticleTypeEntity> page = this.page(
                new Query<TbArticleTypeEntity>().getPage(params),
                new QueryWrapper<TbArticleTypeEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<Map<String, Object>> getAllTypeList() {
        List<Map<String, Object>> list = new ArrayList<>();

        List<TbArticleTypeEntity> entityList = baseMapper.selectList(new QueryWrapper<TbArticleTypeEntity>());
        entityList.stream().forEach(item -> {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("label", item.getTypeNameCn());
            map.put("value", item.getId());
            list.add(map);
        });
        return list;
    }

}